<?php

class KmenusApp extends StoreadminbaseApp {

    var $_store_id;
    var $_kmenus_mod;
    var $_kmenusinfo_mod;

    /* 构造函数 */

    function __construct() {
        $this->KmenusApp();
    }

    function KmenusApp() {
        parent::__construct();
        $this->_store_id = intval($this->visitor->get('manage_store'));
        $this->_kmenus_mod = & m('kmenus');
        $this->_kmenusinfo_mod = & m('kmenusinfo');
    }

    function index() {
        //快捷键内容列表
        $kmenusinfo = $this->_kmenusinfo_mod->find(
                array(
                    'conditions' => 'kmenus_id=' . $this->_store_id
                )
        );
        $this->assign('kmenusinfo', $kmenusinfo);

        $this->_curitem('kmenus');
        $this->_curmenu('kmenus_list');
        $this->_curlocal(LANG::get('member_center'), 'index.php?app=member', LANG::get('kmenus'), 'index.php?app=kmenus', LANG::get('kmenus_list'));
        $this->_config_seo('title', Lang::get('member_center') . ' - ' . Lang::get('kmenus'));
        $this->display('kmenus.index.html');
    }

    function style() {
        if (!IS_POST) {
            //快捷键位置设置
            $kmenus = $this->_kmenus_mod->get($this->_store_id);
            //如果不存在  就新增
            if (empty($kmenus)) {
                $data = array(
                    'kmenus_id' => $this->_store_id,
                    'stypeinfo' => '1',
                    'status' => '0',
                    'stype' => '1',
                );
                $this->_kmenus_mod->add($data);
                $kmenus = $this->_kmenus_mod->get($this->_store_id);
            }
            $this->assign('kmenus', $kmenus);
            $this->_curitem('kmenus');
            $this->_curmenu('kmenus_style');
            $this->_curlocal(LANG::get('member_center'), 'index.php?app=member', LANG::get('kmenus'), 'index.php?app=kmenus', LANG::get('kmenus_style'));
            $this->_config_seo('title', Lang::get('member_center') . ' - ' . Lang::get('kmenus_style'));
            $this->display('kmenus.style.html');
        } else {
            $data = array(
                'stypeinfo' => $_POST['stypeinfo'],
                'status' => $_POST['status'],
                'stype' => $_POST['stype'],
            );
            $this->_kmenus_mod->edit($this->_store_id, $data);
            $this->show_message('edit_ok');
        }
    }

    function add() {
        if (!IS_POST) {
            $this->_curlocal(LANG::get('member_center'), 'index.php?app=member', LANG::get('kmenus'), 'index.php?app=kmenus', LANG::get('kmenus_add'));
            $this->_curitem('kmenus');
            $this->_curmenu('kmenus_add');
            $this->_config_seo('title', Lang::get('member_center') . ' - ' . Lang::get('kmenus_add'));
            $this->display('kmenus.form.html');
        } else {
            $data = array(
                'kmenus_id' => $this->_store_id,
                'title' => $_POST['title'],
                'color' => $_POST['color'],
                'loadurl' => $_POST['loadurl'],
                'imgurl' => $_POST['imgurl'],
                'nums' => $_POST['nums'],
            );
            $this->_kmenusinfo_mod->add($data);
            $this->show_message('add_ok');
        }
    }

    function edit() {
        $id = empty($_GET['id']) ? 0 : intval($_GET['id']);
        $kmenusinfo = $this->_kmenusinfo_mod->get($id);
        if (empty($kmenusinfo) || $kmenusinfo['kmenus_id'] != $this->_store_id) {
            $this->show_warning('Hacking Attempt');
            return;
        }

        if (!IS_POST) {
            $this->assign('kmenusinfo', $kmenusinfo);
            $this->_curlocal(LANG::get('member_center'), 'index.php?app=member', LANG::get('kmenus'), 'index.php?app=kmenus', LANG::get('kmenus_edit'));
            $this->_curitem('kmenus');
            $this->_curmenu('kmenus_edit');
            $this->_config_seo('title', Lang::get('member_center') . ' - ' . Lang::get('kmenus_edit'));
            $this->display('kmenus.form.html');
        } else {
            $data = array(
                'title' => $_POST['title'],
                'color' => $_POST['color'],
                'loadurl' => $_POST['loadurl'],
                'imgurl' => $_POST['imgurl'],
                'nums' => $_POST['nums'],
            );
            $this->_kmenusinfo_mod->edit($id, $data);
            $this->show_message('edit_ok');
        }
    }

    function drop() {
        $id = empty($_GET['id']) ? 0 : intval($_GET['id']);
        $kmenusinfo = $this->_kmenusinfo_mod->get($id);
        if (empty($kmenusinfo) || $kmenusinfo['kmenus_id'] != $this->_store_id) {
            $this->show_warning('Hacking Attempt');
            return;
        }
        $this->_kmenusinfo_mod->drop($id);
        $this->show_message('drop_ok');
    }

    function _get_member_submenu() {
        $menus = array(
            array(
                'name' => 'kmenus_list',
                'url' => 'index.php?app=kmenus',
            ),
            array(
                'name' => 'kmenus_style',
                'url' => 'index.php?app=kmenus&act=style',
            ),
            array(
                'name' => 'kmenus_add',
                'url' => 'index.php?app=kmenus&act=add',
            ),
        );
        if (ACT == 'edit') {
            $menus[] = array(
                'name' => 'kmenus_edit',
                'url' => '',
            );
        }
        return $menus;
    }

}

?>
